package com.cygsunri.parkingucenter.controller;

import com.alibaba.fastjson.JSONObject;
import com.cygsunri.commonutils.response.ResultWrapper;
import com.cygsunri.parkingucenter.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IndexService indexService;

/**
     * 根据token获取用户信息
     */

    @GetMapping("info")
    public ResultWrapper<Object> info(){
        //获取当前登录用户用户名
        String username = SecurityContextHolder.getContext().getAuthentication().getName();
        Map<String, Object> userInfo = indexService.getUserInfo(username);
        return ResultWrapper.ok("根据token获取用户信息成功!",userInfo);
    }

/**
     * 获取菜单
     * @return
     */

    @GetMapping("menu")
    public ResultWrapper<Object> getMenu(){
        //获取当前登录用户用户名
        String username = SecurityContextHolder.getContext().getAuthentication().getName();
        List<JSONObject> permissionList = indexService.getMenu(username);
        return ResultWrapper.ok("获取菜单成功!",permissionList);
    }

}
